/**
 * Desenvolvido pela Fábrica de Software do CESUPA.
 * Todos os direitos reservados.
 */
package br.cesupa.fabsoft.nomedoprojeto.system.infra.view;

import java.text.MessageFormat;

/**
 * Represents a feedback signal from the application back-end. Used by the user
 * interface to show the system current status.
 *
 * @author Breno Leite
 */
public class Message implements Cloneable {

    /**
     * The main text of the message.
     */
    private String text;
    /**
     * The type of the message.
     */
    private MessageType messageType = MessageType.INFO;
    /**
     * Solution for the problem presented in the message.
     */
    private String solution;
    /**
     * Problem´s details.
     */
    private String details;

    /**
     * Creates a message without any kind of details (cane be added later).
     *
     * @param text  the message´s text
     * @param messageType   the message´s type
     */
    public Message(final String text, final MessageType messageType) {
        setText(text);
        setMessageType(messageType);
    }

    /**
     * Creates a info message with a given text.
     * 
     * @param text  the message´s text
     */
    public Message(final String text) {
        setText(text);
        setMessageType(MessageType.INFO);
    }

    /**
     *
     * @return a new message
     * @see Object#clone()
     */
    public Message createClone() {
        Message message = null;

        try {
            message = (Message) this.clone();
        } catch (CloneNotSupportedException exception) {
        }

        return message;
    }

    public boolean isMoreInformationDisponible() {
        return (getDetails() != null || getSolution() != null);
    }

    /**
     * @return the message´s type
     */
    public MessageType getMessageType() {
        return messageType;
    }

    /**
     * @param messageType the type of the message
     */
    public void setMessageType(final MessageType messageType) {
        this.messageType = messageType;
    }

    /**
     * @return the main text of the message
     */
    public String getText() {
        return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }

    @Override
    public String toString() {
        return MessageFormat.format("[{0}]: {1}",
                getMessageType().toString(), getText());
    }

    /**
     * @return the solution
     */
    public String getSolution() {
        return solution;
    }

    /**
     * @param solution the solution to set
     */
    public void setSolution(String solution) {
        this.solution = solution;
    }

    /**
     * @return the details
     */
    public String getDetails() {
        return details;
    }

    /**
     * @param details the details to set
     */
    public void setDetails(String details) {
        this.details = details;
    }
}
